package com.soft.service.impl;

import com.soft.dao.BusinessMapper;

import com.soft.model.Business;
import com.soft.model.BusinessExample;

import com.soft.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    private BusinessMapper mapper;

    @Override
    public Business getById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public Business getByUserName(String username) {
        BusinessExample example = new BusinessExample();
        BusinessExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<Business> users = mapper.selectByExample(example);
        System.out.println(users);
        if (users != null && users.size() > 0) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public List<Business> getAll() {
        return mapper.selectByExample(null);
    }

    @Override
    public int add(Business business) {
        return mapper.insertSelective(business);
    }

    @Override
    public int update(Business business) {
        return mapper.updateByPrimaryKeySelective(business);
    }

    @Override
    public int delete(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

}
